import java.util.Scanner;

public class demo06 {
    //分糖果
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int[] arr=new int[n];
        for (int i = 0; i < n; i++) {
            arr[i]=sc.nextInt();
        }
        int count=0;
        while (true){
            int[] arr1=new int[n];
            for (int i = 0; i < n; i++) {
                arr[i]/=2;
                arr1[i]=arr[i];
            }
            for (int i = 0; i < n; i++) {
                arr[(i+1)%n]+=arr1[i];
            }
            for (int i = 0; i < n; i++) {
                if(arr[i]%2==1){
                    arr[i]+=1;
                    count+=1;
                }
            }
            int flag=1;
            for (int i = 0; i < n-1; i++) {
                if(arr[i]!=arr[i+1]){
                    flag=0;
                    break;
                }
            }
            if(flag==1){
                System.out.println(count);
                break;
            }
        }
    }
}
